home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / buzzmachines_massive.exe / Dev / Geoffroy Notefilter SourceCode / NoteFilter.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-25  |  13.1 KB  |  394 lines

  1. // Copyright (C) Mikko Apo (http://iki.fi/apo/)
  2.  
  3. /*
  4.   Version History:
  5.     1.0 Initial release
  6.   CHANGELOG:
  7.   -
  8.   */
  9.  
  10. #include <stdlib.h>
  11. #include <time.h>
  12. #include <math.h>
  13. #include <string.h>
  14. #include <windows.h>
  15. #include "../mdk.h"
  16.  
  17. #include "NoteFilterTrack.h"
  18. #include "BuzzParameterQ.h"
  19. #include "BuzzParameterDuration.h"
  20. #include "BuzzParameterUnit.h"
  21. #include "BuzzParameterVolume.h"
  22. #include "BuzzParameterFilterType.h"
  23. #include "BuzzParameterSwitchADSR.h"
  24.  
  25. // Machine settings
  26.  
  27. // MT_GENERATOR or MT_EFFECT
  28. #define miMACHINETYPE MT_EFFECT
  29.  
  30. // 0 or some CMachineInfo flags, MIF_DOES_INPUT_MIXING is for effect
  31. #define miMACHINEFLAGS 0|MIF_DOES_INPUT_MIXING
  32.  
  33. #define miMACHINE_NAME "Geoffroy NoteFilter"
  34. #define miSHORT_NAME "NoteFilter"
  35. #define miMACHINE_AUTHOR "Geoffroy Montel (www.minizza.com)"
  36. #define miCOMMAND_STRING "About..."
  37. #define miMAX_TRACKS        10
  38. #define miMIN_TRACKS        1
  39. #define miNUMGLOBALPARAMETERS    19
  40. #define miNUMTRACKPARAMETERS    2
  41. #define miNUMATTRIBUTES        0
  42. #define miVERSION "1.0"
  43. #if miMACHINETYPE == MT_EFFECT
  44. #define miMACHINETYPESTRING "[effect]"
  45. #else
  46. #define miMACHINETYPESTRING "[generator]"
  47. #endif
  48. #define miABOUTTXT miMACHINE_NAME" "miMACHINETYPESTRING"\n\nGeoffroy NoteFilter.dll build date: "__DATE__"\nVersion: "miVERSION"\nCode by: "miMACHINE_AUTHOR"\n"
  49.  
  50. // beta warning displays a nagging requester each time the machine is started
  51. // the requester can be disabled from the attributes
  52. // to enable, set to 1
  53. // firstTick gets compiled in
  54. #define miBETAWARNING 0
  55.  
  56. // machine is always stero if this flag is set to true, only MDKWorkStereo is called
  57. // to enable, set to 1
  58. #define miISALWAYSSTEREO 1
  59.  
  60. // add code which will notice samplerate changes caused by the host
  61. // to enable, set to 1
  62. // mi->samplerate value gets compiled in
  63. //#undef miNOTIFYONSAMPLERATECHANGES
  64. #define miNOTIFYONSAMPLERATECHANGES 1
  65.  
  66. #if miBETAWARNING > 0
  67.  
  68. #define miBETAWARNINGATTRIBUTE 1
  69. CMachineAttribute const attrBetaWarning = { "Disable Preview Warning" ,0,1,0 };
  70. #define miBETAWARNINGTXT "WARNING: This is a preview version of "miMACHINE_NAME" (version "miVERSION ")"\
  71.     "\nDO NOT use this machine in your tracks or they might break\n" \
  72.     "when newer versions are released.\n" \
  73.     "If you use this machine, don't save your song with it.\n" \
  74.     "\n(You can override this warning from the attributes,\n " \
  75.     "but you need to save your song to save the setting.\n" \
  76.     "\n" miMACHINE_AUTHOR " / "__DATE__
  77.  
  78. #else
  79. #define miBETAWARNINGATTRIBUTE 0
  80. #endif
  81.  
  82. //    Parameters
  83.  
  84. /*
  85.  
  86.   // examples
  87.  
  88. CMachineParameter const paraWord = 
  89. { pt_word, "Desc","Long desc",0,0xfffe,0xffff,MPF_STATE,0};
  90.  
  91. CMachineParameter const paraByte = 
  92. { pt_byte, "Desc","Long",0,0xfe,0xff,MPF_STATE,0};
  93.  
  94. CMachineParameter const paraSwitch = 
  95. { pt_switch, "Desc","Long",SWITCH_OFF,SWITCH_ON,SWITCH_NO,MPF_STATE,SWITCH_OFF};
  96.  
  97. CMachineParameter const paraNote = 
  98. { pt_note, "Desc","Long",NOTE_MIN,NOTE_OFF,NOTE_NO,MPF_STATE,10 };
  99. */
  100.  
  101.     // insert your own parameters below
  102.  
  103. CMachineParameter const paraFilterType = 
  104. { pt_byte, "Filter","Filter type",BuzzParameterFilterType.MIN_SLIDER_VALUE,BuzzParameterFilterType.MAX_SLIDER_VALUE,BuzzParameterFilterType.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterFilterType::INIT_SLIDER_VALUE};
  105.  
  106. CMachineParameter const paraQ = 
  107. { pt_word, "Q","Q",BuzzParameterQ.MIN_SLIDER_VALUE,BuzzParameterQ.MAX_SLIDER_VALUE,BuzzParameterQ.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterQ::INIT_SLIDER_VALUE};
  108.  
  109. CMachineParameter const paraUnit = 
  110. { pt_byte, "Unit","Unit for inertia",BuzzParameterUnit.MIN_SLIDER_VALUE,BuzzParameterUnit.MAX_SLIDER_VALUE,BuzzParameterUnit.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterUnit::INIT_SLIDER_VALUE};
  111.  
  112. CMachineParameter const paraInertia = 
  113. { pt_word, "Inertia","Inertia",BuzzParameterDuration.MIN_SLIDER_VALUE,BuzzParameterDuration.MAX_SLIDER_VALUE,BuzzParameterDuration.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterDuration::INIT_SLIDER_VALUE};
  114.  
  115. CMachineParameter const paraVolumeHarmo0 = 
  116. { pt_word, "Fundamental","Fundamental Volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  117.  
  118. CMachineParameter const paraVolumeHarmo1 = 
  119. { pt_word, "1st harmo","1st harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  120.  
  121. CMachineParameter const paraVolumeHarmo2 = 
  122. { pt_word, "2nd harmo","2nd harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  123.  
  124. CMachineParameter const paraVolumeHarmo3 = 
  125. { pt_word, "3nd harmo","3rd harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  126.  
  127. CMachineParameter const paraVolumeHarmo4 = 
  128. { pt_word, "4th harmo","4th harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  129.  
  130. CMachineParameter const paraVolumeHarmo5 = 
  131. { pt_word, "5th harmo","5th harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  132.  
  133. CMachineParameter const paraVolumeHarmo6 = 
  134. { pt_word, "6th harmo","6th harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  135.  
  136. CMachineParameter const paraVolumeHarmo7 = 
  137. { pt_word, "7th harmo","7th harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  138.  
  139. CMachineParameter const paraVolumeHarmo8 = 
  140. { pt_word, "8th harmo","8th harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  141.  
  142. CMachineParameter const paraVolumeHarmo9 = 
  143. { pt_word, "9th harmo","9th harmonic volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  144.  
  145. CMachineParameter const paraSwitchADSR = 
  146. { pt_byte, "ADSR","ADSR",BuzzParameterSwitchADSR.MIN_SLIDER_VALUE,BuzzParameterSwitchADSR.MAX_SLIDER_VALUE,BuzzParameterSwitchADSR.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterSwitchADSR::INIT_SLIDER_VALUE};
  147.  
  148. CMachineParameter const paraA = 
  149. { pt_word, "A","A",BuzzParameterDuration.MIN_SLIDER_VALUE,BuzzParameterDuration.MAX_SLIDER_VALUE,BuzzParameterDuration.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterDuration::INIT_SLIDER_VALUE};
  150.  
  151. CMachineParameter const paraD = 
  152. { pt_word, "D","D",BuzzParameterDuration.MIN_SLIDER_VALUE,BuzzParameterDuration.MAX_SLIDER_VALUE,BuzzParameterDuration.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterDuration::INIT_SLIDER_VALUE};
  153.  
  154. CMachineParameter const paraS = 
  155. { pt_word, "S","S",BuzzParameterDuration.MIN_SLIDER_VALUE,BuzzParameterDuration.MAX_SLIDER_VALUE,BuzzParameterDuration.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterDuration::INIT_SLIDER_VALUE};
  156.  
  157. CMachineParameter const paraR = 
  158. { pt_word, "R","R",BuzzParameterDuration.MIN_SLIDER_VALUE,BuzzParameterDuration.MAX_SLIDER_VALUE,BuzzParameterDuration.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterDuration::INIT_SLIDER_VALUE};
  159.  
  160. CMachineParameter const paraNote = 
  161. { pt_note, "Note","Note",NOTE_MIN,NOTE_OFF,NOTE_NO,0,0 };
  162.  
  163. CMachineParameter const paraTrackVolume = 
  164. { pt_word, "Volume","Volume",BuzzParameterVolume.MIN_SLIDER_VALUE,BuzzParameterVolume.MAX_SLIDER_VALUE,BuzzParameterVolume.UNCHANGED_SLIDER_VALUE,MPF_STATE,BuzzParameterVolume::INIT_SLIDER_VALUE};
  165.  
  166.     // end of insert
  167.  
  168. // List of all parameters, track parameters last
  169.  
  170. CMachineParameter const *pParameters[] = {
  171. #if (miNUMGLOBALPARAMETERS + miNUMTRACKPARAMETERS) == 0
  172.     NULL
  173. #endif
  174.  
  175.     // ¶Word,¶Byte,¶Switch,¶Note // example
  176.     // insert your own parameters below
  177.     
  178.     ¶FilterType,¶Q,¶Unit,¶Inertia,
  179.     ¶VolumeHarmo0,¶VolumeHarmo1,¶VolumeHarmo2,¶VolumeHarmo3,¶VolumeHarmo4,
  180.     ¶VolumeHarmo5,¶VolumeHarmo6,¶VolumeHarmo7,¶VolumeHarmo8,¶VolumeHarmo9,
  181.     ¶SwitchADSR,¶A,¶D,¶S,¶R,
  182.     ¶Note,¶TrackVolume
  183.  
  184.     // end of insert
  185. };
  186.  
  187. // This assigns a number to the parameter, used by DescribeValue
  188. // Fill in your own parameters
  189. // used by Decribe() and maybe other places
  190. // enum {PARAM_WORD,PARAM_BYTE,PARAM_SWITCH,PARAM_NOTE} miPARAMETERS;
  191. enum {PARAM_FILTERTYPE,PARAM_Q,PARAM_UNIT,PARAM_INERTIA,
  192. PARAM_VOLUMEHARMO_0,PARAM_VOLUMEHARMO_1,PARAM_VOLUMEHARMO_2,PARAM_VOLUMEHARMO_3,PARAM_VOLUMEHARMO_4,
  193. PARAM_VOLUMEHARMO_5,PARAM_VOLUMEHARMO_6,PARAM_VOLUMEHARMO_7,PARAM_VOLUMEHARMO_8,PARAM_VOLUMEHARMO_9,
  194. PARAM_SWITCH_ADSR,PARAM_A,PARAM_D,PARAM_S,PARAM_R,
  195. PARAM_NOTE,PARAM_TRACK_VOLUME} miPARAMETERS;
  196.  
  197. // Attributes
  198.  
  199.     // CMachineAttribute const attrTime = { "Time in ms" ,0,128,0 };
  200.     // insert your own attributes below
  201.  
  202.  
  203.     // end of insert
  204.  
  205. // List of all attributes
  206.  
  207. CMachineAttribute const *pAttributes[] = {
  208. #if (miNUMATTRIBUTES + miBETAWARNINGATTRIBUTE )== 0
  209.     NULL
  210. #endif
  211.  
  212.     //    &attrTime    // Example
  213.     // insert your own attributes below
  214.  
  215.  
  216.     // end of insert
  217.  
  218. #if miBETAWARNING > 0
  219. #if miNUMATTRIBUTES > 0
  220. ,
  221. #endif
  222. // beta warning belongs to as the last attribute
  223.     &attrBetaWarning
  224. #endif
  225. };
  226.  
  227. #pragma pack(1)
  228.  
  229. #if miNUMGLOBALPARAMETERS>0
  230.  
  231. // storage for global parameters, updated every Tick()
  232. class gvals {
  233. public:
  234. //    word wordparam;        // word        // Example
  235. //    byte byteparam;        // byte
  236. //    byte switchparam;    // switch
  237. //    byte noteparam;        // note
  238.  
  239.     // insert your global parameters here
  240.  
  241.     byte filtertype;
  242.     word q;
  243.     byte unit;
  244.     word inertia;
  245.     word harmovolume[NoteFilterTrack_NB_HARMONICS];
  246.     byte switchADSR;
  247.     word a;
  248.     word d;
  249.     word s;
  250.     word r;
  251.  
  252.     // end of insert
  253. };
  254. #endif
  255.  
  256. #if (miMAX_TRACKS>0 && miNUMTRACKPARAMETERS>0)
  257.  
  258. // storage for track parameters, updated every Tick()
  259. class tvals {
  260. public:
  261.     // insert your track parameters here
  262.  
  263.     byte note;
  264.     word volume;
  265.     // end of insert
  266. };
  267. #endif
  268.  
  269. #if (miNUMATTRIBUTES + miBETAWARNINGATTRIBUTE )>0
  270.  
  271. // storage for attributes, updated after MDKInit() and AttributesChanged
  272. class avals {
  273. public:
  274. //     int time;    // example
  275.  
  276.  
  277.     // insert your attribute parameters here
  278.  
  279.  
  280.     // end of insert
  281.  
  282. #if miBETAWARNING >0
  283.     int betawarning;
  284. #endif
  285. };
  286. #endif
  287.  
  288. #pragma pack()
  289.  
  290.  
  291. // Machine's info
  292.  
  293. CMachineInfo const MacInfo = {
  294.     miMACHINETYPE,MI_VERSION,miMACHINEFLAGS,miMIN_TRACKS,miMAX_TRACKS,
  295.     miNUMGLOBALPARAMETERS,miNUMTRACKPARAMETERS,pParameters,
  296.     miNUMATTRIBUTES+miBETAWARNINGATTRIBUTE,pAttributes,
  297.     miMACHINE_NAME
  298. #ifdef _DEBUG
  299.     " [DEBUG]"
  300. #endif
  301.     ,miSHORT_NAME,miMACHINE_AUTHOR,miCOMMAND_STRING
  302. };
  303.  
  304. class miex : public CMDKMachineInterfaceEx {
  305.  
  306. };
  307.  
  308. class mi : public CMDKMachineInterface {
  309. public:
  310.     mi();
  311.     ~mi();
  312.  
  313. // Buzz calls these functions
  314.     void Command(int const i);
  315.     void Tick();
  316.     char const *DescribeValue(int const param, int const value);
  317.     void MDKInit(CMachineDataInput * const pi);
  318.     bool MDKWork(float *psamples, int numsamples, int const mode);
  319.     bool MDKWorkStereo(float *psamples, int numsamples, int const mode);
  320.     void MDKSave(CMachineDataOutput * const po) { }
  321.     CMDKMachineInterfaceEx *GetEx() { return &ex; }
  322.     void OutputModeChanged(bool stereo);
  323.     void AttributesChanged();
  324.     void MidiNote(int const channel, int const value, int const velocity);
  325.     void Stop();
  326.  
  327.     public:
  328.         void filterTypeChanged();
  329.     miex ex;
  330. #if miNUMGLOBALPARAMETERS>0
  331.     gvals gval;
  332. #endif
  333. #if (miNUMATTRIBUTES + miBETAWARNINGATTRIBUTE )>0
  334.     avals aval;
  335. #endif
  336. #if (miMAX_TRACKS>0 && miNUMTRACKPARAMETERS>0)
  337.     void SetNumTracks(int const n);
  338.     tvals tval[miMAX_TRACKS];
  339. #endif
  340.  
  341. private:
  342.  
  343.  
  344. #if (miMAX_TRACKS>0 && miNUMTRACKPARAMETERS>0)
  345.     unsigned int miNumberOfTracks;    // contains the number of tracks in use
  346. #endif
  347.  
  348. #if (miBETAWARNING)> 0
  349.     bool firstTick;
  350. #endif
  351.  
  352. #if miNOTIFYONSAMPLERATECHANGES>0
  353.     unsigned int samplerate;
  354. #endif
  355.  
  356.     unsigned int samplesPerTick;
  357.  
  358.     // insert your machine's global variables here
  359.  
  360.     BuzzParameterFilterType filterType;
  361.     BuzzParameterQ q;
  362.     BuzzParameterDuration inertia;
  363.     BuzzParameterUnit unit;
  364.     BuzzParameterVolume harmoVolumes[NoteFilterTrack_NB_HARMONICS];
  365.     BuzzParameterDuration a;
  366.     BuzzParameterDuration d;
  367.     BuzzParameterDuration s;
  368.     BuzzParameterDuration r;
  369.     BuzzParameterSwitchADSR switchADSR;
  370.  
  371.     float * trackBufferTemp;
  372.     int trackBufferTempSize;
  373.     float * mixBufferTemp;
  374.     int mixBufferTempSize;
  375.  
  376.     // end of insert
  377.  
  378. #if (miMAX_TRACKS>0 && miNUMTRACKPARAMETERS>0)
  379.     struct mytvals {
  380.     // insert your machine's track's own variables here
  381.  
  382.     NoteFilterTrack noteFilterTrack;    
  383.     BuzzParameterVolume volume;
  384.  
  385.     // end of insert
  386.     } mytval[miMAX_TRACKS];
  387. #endif
  388.  
  389. protected:
  390.     void unitChanged();
  391.     void inertiaChanged();
  392. };
  393.  
  394.